package com.nkzy.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * Create by 王建烨 on 2022/4/2 9:32
 **/

@RestController
public class UploadController {

    @Value("${file.path}")
    private String fileUploadPath;

    @PostMapping("/fileUpload")
    public String fileUpload(MultipartFile file_upload) throws IOException {
        // 创建一个文件流对象
        File fileUploadDir = new File(fileUploadPath);
        // 判断文件夹是否存在
        if(!fileUploadDir.exists()){
            fileUploadDir.mkdir();
        }
        // 将上传的文件保存到指定文件夹
        file_upload.transferTo(new File(fileUploadDir +"\\"+ file_upload.getOriginalFilename()));
        return "上传成功";
    }
}
